import 'package:flutter/material.dart';
import 'package:my_app/conponate/user_info.dart';
import 'package:my_app/pages/star_rubbishs.dart';
import 'login.dart';
import 'development_of_information.dart';
import 'feedback.dart';
import 'draw_layout.dart';
import 'change_passward.dart';

class GeneralUserPage extends StatefulWidget {
  const GeneralUserPage({Key? key}) : super(key: key);

  @override
  _GeneralUserPageState createState() => _GeneralUserPageState();
}

class _GeneralUserPageState extends State<GeneralUserPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // backgroundColor: Colors.black87,
        appBar: (AppBar(
          backgroundColor: Colors.blueGrey,
          leading: Builder(builder: (BuildContext context) {
            return IconButton(
                icon: Icon(Icons.view_headline_rounded),
                onPressed: () {
                  Scaffold.of(context).openDrawer();
                });
          }),
          title: Text(
            "用户",
          ),
          centerTitle: true,
          elevation: 5.0,
        )),
        drawer: DrawLayout(),
        body: Column(
          children: [
            SizedBox(
              height: 20,
            ),
            UserAccountsDrawerHeader(
              margin: const EdgeInsets.only(bottom: 20),
              accountName: Text(
                UserInfo.userName,
                style: TextStyle(
                  fontSize: 20,
                  fontWeight: FontWeight.bold,
                  color: const Color(0xffb6ad90),
                ),
              ),
              accountEmail: Text(
                "",
                style: TextStyle(
                  fontSize: 16,
                  color: const Color(0xffb6ad90),
                ),
              ),
              currentAccountPicture: FittedBox(
                fit: BoxFit.cover,
                child: CircleAvatar(
                  child: Icon(
                    Icons.person,
                    color: Colors.white,
                  ),
                  backgroundColor: const Color(0xffb6ad90),
                  radius: 20,
                ),
              ),
              decoration: BoxDecoration(
                color: Colors.blueGrey,
              ),
            ),
            SizedBox(height: 10),
            GeneralOptionsRows(
                address: DevelopmentOfInformation(), text: '开发信息'),
            SizedBox(height: 20),
            GeneralOptionsRows(address: FeedbackPage(), text: '意见反馈'),
            SizedBox(height: 20),
            GeneralOptionsRows(address: StarRubbishs(), text: '收藏'),
            SizedBox(height: 20),
            GeneralOptionsRows(address: ChangePasswardPage(), text: '修改密码'),
            SizedBox(height: 8),
          ],
        )
    );
  }
}

class GeneralOptionsRows extends StatefulWidget {
  final String text;
  final Widget address;
  const GeneralOptionsRows({required this.text, required this.address});

  @override
  _GeneralOptionsRowsState createState() {
    return _GeneralOptionsRowsState(this.text, this.address);
  }
}

class _GeneralOptionsRowsState extends State<GeneralOptionsRows> {
  late String _text;
  late Widget _address;
  _GeneralOptionsRowsState(String text, Widget address) {
    this._text = text;
    this._address = address;
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.fromLTRB(40, 0, 40, 0),
      child: Row(
        children: [
          Expanded(
            child: OutlineButton(
              color: const Color(0xffb6ad90),
              onPressed: () {
                Navigator.of(context).push(
                  MaterialPageRoute(
                    builder: (context) {
                      return _address;
                    },
                  ),
                );
              },
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(10),
                side: BorderSide(
                  width: 20,
                  color: const Color(0xffb6ad90),
                  style: BorderStyle.solid,
                ),
              ),
              child: Container(
                height: 60,
                alignment: Alignment.center,
                child: Text(
                  _text,
                  style: TextStyle(
                      fontSize: 18,
                      fontWeight: FontWeight.bold,
                      color: const Color(0xffb6ad90),),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
